<?php
require_once ('scripts.php');
$action=$_REQUEST['action'];
	if($action=='getAllMakes')
	{   
		$start=$_POST['start'];
	    $count=$_POST['count'];
	    $searchkey=$_POST['searchkey'];
        $resultArrCol = MakeDAOImpl::getInstance()->getAllMakes($start, $count, $searchkey);
           
		$data = array("makes"=>$resultArrCol->makes, "count"=>$resultArrCol->count);
		echo json_encode($data);
	}
	
	if($action=='getMakes')
	{   

        $data = MakeDAOImpl::getInstance()->getMakes();
           
		$result = array("makes"=>$data);
		echo json_encode($result);
	}
	
	if($action=='getAllModels')
	{   
		$start=$_POST['start'];
	    $count=$_POST['count'];
	    $searchkey=$_POST['searchkey'];
        $resultArrCol = ModelDAOImpl::getInstance()->getAllModels($start, $count, $searchkey);
           
		$data = array("models"=>$resultArrCol->models, "count"=>$resultArrCol->count);
		echo json_encode($data);
	}
	
	if($action=='deleteMake')
	{   
		$makeID=$_POST['makeID'];
        $result = MakeDAOImpl::getInstance()->deleteMake($makeID);
           
		$data = array("result"=>$result);
		echo json_encode($data);
	}
	
	if($action=='deleteModel')
	{   
		$modelID=$_POST['modelID'];
        $result = ModelDAOImpl::getInstance()->deleteModel($modelID);
           
		$data = array("result"=>$result);
		echo json_encode($data);
	}
	
	if($action=='addMake')
	{   
		$makeVO = new MakeVO();
		
		$makeVO->make = $_POST['make'];
		$makeVO->description = $_POST['description'];
		$makeVO->createdBy = $_POST['created_by'];

        $result = MakeDAOImpl::getInstance()->addMake($makeVO);
           
		$data = array("result"=>$result);
		echo json_encode($data);
	}
	
	if($action=='addModel')
	{   
		$modelVO = new ModelVO();
		
		$modelVO->makeID = $_POST['makeID'];
		$modelVO->model = $_POST['model'];
		$modelVO->description = $_POST['description'];
		$modelVO->createdBy = $_POST['created_by'];

        $result = ModelDAOImpl::getInstance()->addModel($modelVO);
           
		$data = array("result"=>$result);
		echo json_encode($data);
	}
	
	if($action=='editModel')
	{   
		$modelVO = new ModelVO();
		
		$modelVO->modelID = $_POST['modelID'];
		$modelVO->makeID = $_POST['makeID'];
		$modelVO->model = $_POST['model'];
		$modelVO->description = $_POST['description'];
		$modelVO->editedBy = $_POST['updatedBy'];

        $result = ModelDAOImpl::getInstance()->editModel($modelVO);
           
		$data = array("result"=>$result);
		echo json_encode($data);
	}
	
	if($action=='editMake')
	{   
		$makeVO = new MakeVO();
		
		$makeVO->makeID = $_POST['makeID'];
		$makeVO->make = $_POST['make'];
		$makeVO->description = $_POST['description'];
		$makeVO->editedBy = $_POST['updateBy'];

        $result = MakeDAOImpl::getInstance()->editMake($makeVO);
           
		$data = array("result"=>$result);
		echo json_encode($data);
	}
	
?>